home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / proc / procTypes.h < prev    next >
C/C++ Source or Header  |  1991-05-06  |  18KB  |  563 lines

  1. /*
  2.  * procTypes.h --
  3.  *
  4.  *    External declarations of data structures
  5.  *    for managing processes.
  6.  *
  7.  * Copyright 1986, 1988 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  *
  17.  * rcsid $Header: /sprite/src/kernel/proc/RCS/procTypes.h,v 1.7 91/05/06 14:42:04 kupfer Exp $ SPRITE (Berkeley)
  18.  */
  19.  
  20. #ifndef _PROCTYPES
  21. #define _PROCTYPES
  22.  
  23. #ifdef KERNEL
  24. #include <user/proc.h>
  25. #include <user/sync.h>
  26. #include <syncLock.h>
  27. #include <list.h>
  28. #include <timer.h>
  29. #include <sigTypes.h>
  30. #include <machTypes.h>
  31. #include <sysSysCallParam.h>
  32. #else
  33. #include <proc.h>
  34. #include <sync.h>
  35. #include <kernel/syncLock.h>
  36. #include <list.h>
  37. #include <kernel/timer.h>
  38. #include <kernel/sigTypes.h>
  39. #include <kernel/machTypes.h>
  40. #endif /* */
  41.  
  42. /*
  43.  * Constants for Proc_Exec().  
  44.  *
  45.  * PROC_MAX_EXEC_ARG_LENGTH    The maximum length of all arguments that are
  46.  *                passed to exec.  Also used to bound any
  47.  *                individual argument.
  48.  * PROC_MAX_EXEC_ARGS        The maximum number of arguments that can be
  49.  *                passed to an exec'd process.  By making it
  50.  *                the same, each argument could conceivably be
  51.  *                a single byte.
  52.  */
  53.  
  54. #define    PROC_MAX_EXEC_ARG_LENGTH    20480
  55. #define    PROC_MAX_EXEC_ARGS        20480
  56.  
  57. /*
  58.  * Masks to extract the proc table index and the generation number from
  59.  * a process id.  Process IDs need to be unique across reuses of the same
  60.  * procTable slot, and they need to be unique from host to host.
  61.  */
  62.  
  63. /*
  64.  * PROC_INDEX_MASK is defined in user/proc.h.
  65.  * #define    PROC_INDEX_MASK        0x000000FF
  66.  */
  67. #define    PROC_ID_NUM_MASK    0x0000FF00
  68. #define PROC_ID_NUM_SHIFT    8
  69. #define    PROC_GEN_NUM_MASK    0x000F0000
  70. #define PROC_GEN_NUM_SHIFT    16
  71.  
  72.  
  73. /*
  74.  * Number of locks that can be pushed on the lock stack for a process. The
  75.  * stack is used in the sync module to determine the locking structure of the
  76.  * system.
  77.  */
  78. #define PROC_LOCKSTACK_SIZE 10
  79.  
  80.  
  81. /* DATA STRUCTURES */
  82.  
  83. /*
  84.  * Structure passed to the function called by Proc_CallFunc.
  85.  */
  86. typedef struct {
  87.     unsigned int    interval;    /* Set by func to cause it to be 
  88.                      * rescheduled. */
  89.     ClientData        clientData;    /* Data given to Proc_CallFunc*(). */
  90.     ClientData        token;        /* Unique token to identify this call.*/
  91. } Proc_CallInfo;
  92.  
  93. /*
  94.  * Structure to describe an environment.
  95.  */
  96.  
  97. typedef struct {
  98.     int            refCount;    /* Number of processes using this 
  99.                      * environment. */
  100.     int            size;        /* Number of elements in environment. */
  101.     struct ProcEnvironVar *varArray;    /* The environment itself. */
  102. } Proc_EnvironInfo;
  103.  
  104. /*
  105.  * >>> Process state flags have been moved to user/proc.h <<<
  106.  */
  107.  
  108. /*
  109.  *  Proc_PCBLinks is used to link the PCB entry into various doubly-linked
  110.  *  lists. For example, processes waiting on an event are linked togther.
  111.  */
  112.  
  113. typedef struct {
  114.     List_Links links;            /* Linked list for the hash chain. */
  115.     struct Proc_ControlBlock *procPtr;    /* Back pointer to this structure. */
  116. } Proc_PCBLink;
  117.  
  118.  
  119. /*
  120.  * Proc_Time is used to represent time such that it can be understood
  121.  * by users through Proc_GetPCBInfo in a machine independent format and
  122.  * by the kernel in a machine dependent ticks format.  Thus all users of
  123.  * Proc_Time in the kernel should always use the ticks field and user
  124.  * programs that call Proc_GetPCBInfo should use the time field.
  125.  */
  126. typedef union {
  127.     Timer_Ticks    ticks;    /* The kernel's notion of time. */
  128.     Time    time;    /* The user's notion of time. */
  129. } Proc_Time;
  130.  
  131. typedef struct {
  132.     int        type;        /* type of lock */
  133.     Address    lockPtr;    /* Ptr to lock */
  134. } Proc_LockStackElement;
  135.  
  136. /*
  137.  *  The Proc_ControlBlock structure:
  138.  *   It contains information to manage the process such as virtual 
  139.  *   memory usage, cpu usage, scheduling info, process state, 
  140.  *   which processor the process is executing on, etc.
  141.  */
  142.  
  143. typedef struct Proc_ControlBlock {
  144.     List_Links    links;        /* Used to link processes together. */
  145.  
  146.     int        processor;    /* Processor number the process is running on
  147.                  * or wants to run on if the processor is
  148.                  * available.  */
  149.  
  150.     Proc_State    state;        /* Describes a process's current running state.
  151.                  * >>> See Proc_State definitions in
  152.                  * >>> user/proc.h. */ 
  153.  
  154.     int        genFlags;    /* Flags to describe a processes overall state.
  155.                  * >>> See definitions in user/proc.h. */ 
  156.     int        syncFlags;    /* Flags used by the sync module. */
  157.     int        schedFlags;    /* Flags used by the sched module. */
  158.     int        exitFlags;    /* Flags used by the exit-detach-
  159.                   * wait monitor. */
  160.  
  161.     List_Links        childListHdr;    /* Header for list of children. */
  162.     List_Links        *childList;    /* Pointer to header of list. */
  163.     Proc_PCBLink    siblingElement;    /* Element in list of sibling 
  164.                      * processes. */
  165.     Proc_PCBLink    familyElement;    /* Element in a list of family
  166.                        members. */
  167.  
  168.     /*
  169.      *-----------------------------------------------------------------
  170.      *
  171.      *   Various Process Identifiers.
  172.      *    
  173.      *    Note that the user and effectiveUser ID are kept here because
  174.      *    they are used for permission checking in various places.  There
  175.      *    is also a list of group IDs which is kept in the filesystem state.
  176.      *
  177.      *-----------------------------------------------------------------
  178.      */
  179.  
  180.     Proc_PID    processID;        /* Actual process ID of this
  181.                      * process (for migrated processes
  182.                      * this is different than the PID
  183.                      * that the user sees). */
  184.     Proc_PID    parentID;        /* The process ID of the parent 
  185.                      * of this process. */
  186.     int        familyID;        /* The id of the process family that 
  187.                      * this process belongs to. */
  188.     int        userID;            /* The user id is used to check access
  189.                      * rights to files and check ability
  190.                      * to signal other processes. */
  191.     int        effectiveUserID;    /* The effective user id is used
  192.                      * for setuid access. */
  193.  
  194.     /*
  195.      *-----------------------------------------------------------------
  196.      *
  197.      *    Synchronization fields.
  198.      *
  199.      * Synchronization state includes an event the process is waiting on.
  200.      * PCB's are linked into a hash chain keyed on this event.
  201.      *
  202.      *-----------------------------------------------------------------
  203.      */
  204.  
  205.     int         event;         /* Event # the process is waiting for. */
  206.     Proc_PCBLink eventHashChain; /* Hash chain this PCB is linked to */
  207.  
  208.     /*
  209.      * Monitor conditions for locking this PCB entry.
  210.      */
  211.  
  212.     Sync_Condition    waitCondition;
  213.     Sync_Condition    lockedCondition;
  214.  
  215.     /*
  216.      * Fields for remote waiting.  A token is kept to guard against the
  217.      * race between the wakeup message and the process's decision to sleep.
  218.      */
  219.  
  220.     int            waitToken;
  221.  
  222.     /*
  223.      *-----------------------------------------------------------------
  224.      *
  225.      *    Scheduling fields.
  226.      *
  227.      *-----------------------------------------------------------------
  228.      */
  229.  
  230.  
  231.     int      billingRate;    /* Modifies the scheduler's calculation of
  232.                  * the processes priority.  */
  233.     unsigned int recentUsage;    /* Amount of CPU time used recently */
  234.     unsigned int weightedUsage;    /* Smoothed avg. of CPU usage, weighted by
  235.                  * billing rate. */
  236.     unsigned int unweightedUsage; /* Smoothed avg. of CPU usage, not weighted by
  237.                    * billing rate. */
  238.  
  239.     /*
  240.      *-----------------------------------------------------------------
  241.      *
  242.      *    Accounting and Resource Usage fields.
  243.      *
  244.      *-----------------------------------------------------------------
  245.      */
  246.  
  247.     Proc_Time kernelCpuUsage;    /* How much time has been spent in kernel mode*/
  248.     Proc_Time userCpuUsage;    /* How much time has been spent in user mode. */
  249.  
  250.     Proc_Time childKernelCpuUsage;    /* Sum of time spent in kernel mode for 
  251.                       * all terminated children. */
  252.     Proc_Time childUserCpuUsage;    /* Sum of time spent in user mode for
  253.                       * all terminated children. */
  254.     int     numQuantumEnds;        /* number of times the process was 
  255.                       * context switched due to a quantum 
  256.                      * end. */
  257.     int        numWaitEvents;        /* number of times the process was
  258.                      * context switched due to its waiting 
  259.                      * for an event. */
  260.     unsigned int schedQuantumTicks;    /* Number of clock ticks until this 
  261.                      * process is due to be switched out. */
  262.  
  263.  
  264.     /*
  265.      *-----------------------------------------------------------------
  266.      *
  267.      *   Machine-Dependent fields.
  268.      *
  269.      *    General processor registers, stack information.
  270.      *
  271.      *-----------------------------------------------------------------
  272.      */ 
  273.     struct    Mach_State    *machStatePtr;
  274.  
  275.  
  276.     /*
  277.      *-----------------------------------------------------------------
  278.      *
  279.      *   Virtual Memory fields.
  280.      *
  281.      *-----------------------------------------------------------------
  282.      */
  283.     struct    Vm_ProcInfo    *vmPtr;
  284.  
  285.     /*
  286.      *-----------------------------------------------------------------
  287.      *
  288.      *   I/O and File System fields.
  289.      *
  290.      *-----------------------------------------------------------------
  291.      */
  292.  
  293.     struct Fs_ProcessState    *fsPtr;
  294.  
  295.     /*
  296.      *-----------------------------------------------------------------
  297.      *
  298.      *   Termination Reason, Status and Status Subcode Information.
  299.      *
  300.      *-----------------------------------------------------------------
  301.      */
  302.  
  303.     int    termReason;        /* Reason why process has died or
  304.                  * it has been detached. */
  305.                 /* >>> See definitions in procUser.h */
  306.     int    termStatus;        /* Exit/detach status or signal number
  307.                  * that caused the process to die. */
  308.                 /* >>> See definitions in procUser.h */
  309.     int    termCode;        /* The code for the signal. */
  310.                 /* >>> See definitions in procUser.h */
  311.  
  312.  
  313.     /*
  314.      *-----------------------------------------------------------------
  315.      *
  316.      *    Signals
  317.      *
  318.      *-----------------------------------------------------------------
  319.      */
  320.  
  321.     int        sigHoldMask;        /* Mask of signals to be held. */
  322.     int        sigPendingMask;        /* Mask of pending signals. */
  323.                         /* Array of the different types
  324.                        of actions for signals. */
  325.     int        sigActions[SIG_NUM_SIGNALS];
  326.                         /* Array of signal hold masks for 
  327.                        signal handlers. */
  328.     int        sigMasks[SIG_NUM_SIGNALS];
  329.                     /* Array of signal handlers for 
  330.                        signals. */
  331.     int        sigCodes[SIG_NUM_SIGNALS];
  332.     int        sigFlags;        /* Flags to indicate the signal 
  333.                        state. */
  334.     int        oldSigHoldMask;        /* Mask of held signals when a
  335.                        Sig_Pause call starts. */
  336.     int        sigAddr;        /* Address of the fault. */
  337.  
  338.     /*
  339.      * Info for interval timers. The timer info is not put directly in
  340.      * this struct so additional timers can be added without extending
  341.      * the struct. This information is used to deliver the SIG_TIMER signal
  342.      * to the process.
  343.      */
  344.     struct ProcIntTimerInfo    *timerArray;
  345.  
  346.     /*
  347.      *---------------------------------------------------------------------
  348.      *
  349.      * Data for process migration.
  350.      *
  351.      *---------------------------------------------------------------------
  352.      */
  353.     int            peerHostID;    /* If on home node, ID of remote node.
  354.                      * If on remote node, ID of home node.
  355.                      * If not migrated, undefined. */
  356.     Proc_PID        peerProcessID;     /* If on remote note, process ID on
  357.                      * home node, and vice-versa. */
  358.     struct Proc_ControlBlock
  359.                  *rpcClientProcess;    /* procPtr for migrated process
  360.                      * performing system call, if
  361.                      * applicable. */
  362.  
  363.     /*
  364.      *---------------------------------------------------------------------
  365.      *
  366.      *  Miscellaneous items:
  367.      *
  368.      *---------------------------------------------------------------------
  369.      */
  370.  
  371.     /*
  372.      * Info that describes the process's environment variable table.
  373.      */
  374.     Proc_EnvironInfo    *environPtr;
  375.  
  376.     /*
  377.      * Arguments for the process, taken from Proc_Exec.
  378.      */
  379.     char    *argString;
  380.  
  381. #ifdef LOCKDEP
  382.     /*
  383.      * Stack of locks that process has grabbed.
  384.      */
  385.      Proc_LockStackElement    lockStack[PROC_LOCKSTACK_SIZE];
  386.      int            lockStackSize;
  387. #endif
  388.  
  389. #ifndef CLEAN_LOCK
  390.     /*
  391.      * Information on contention for PCB locks. PCB locks are implemented
  392.      * as a bit in the genflag field and don't use the standard locking
  393.      * stuff. The following field is used to keep lock information. 
  394.      * Its type is Sync_Semaphore, but it is not used as such.
  395.      */
  396.      Sync_Semaphore        lockInfo;
  397. #endif
  398.  
  399.     /*
  400.      * Used to speed up basic kernel-call processing.  These two fields
  401.      * must be next to each other in the table, and in the order below.
  402.      * If you change this, you'll have to change the assembler code that
  403.      * takes kernel-call traps.
  404.      */
  405.  
  406.     ReturnStatus (**kcallTable)();    /* Pointer to array of addresses,
  407.                      * which are procedures to handle
  408.                      * the various kernel calls.  Points
  409.                      * to a different place for migrated
  410.                      * processes than for processes running
  411.                      * at home. */
  412.     int specialHandling;        /* If non-zero, means the process
  413.                      * requires special (slower) handling
  414.                      * (deliver signal, switch contexts,
  415.                      * etc.) on return from the next kernel
  416.                      * call. */
  417.  
  418.     /*
  419.      *---------------------------------------------------------------------
  420.      *
  421.      *  User level profiling information
  422.      *
  423.      *---------------------------------------------------------------------
  424.      */
  425.  
  426.      short *Prof_Buffer;    /* Pointer to an array of profiling information
  427.                              * in the process's address space. */
  428.      int Prof_BufferSize;   /* The size of Prof_Buffer. */
  429.      int Prof_Offset;       /* Value subtracted from the program counter */
  430.      int Prof_Scale;        /* 16 bit fixed point fraction.  Scales the PC
  431.                              * to fit in the Prof_Buffer */
  432.      int Prof_PC;           /* Program counter recorded during the last
  433.                              * timer tick. */
  434.  
  435.     /*
  436.      * This needs to go with the other migration stuff but can't without
  437.      * a world recompile.
  438.      */
  439.     Address    remoteExecBuffer;     /* Buffer to store info for remote
  440.                       * exec prior to migration. */
  441.     Address    migCmdBuffer;         /* Buffer to store multi-part
  442.                       * migration command. */
  443.     int        migCmdBufSize;         /* Size of migCmdBuffer, for
  444.                       * sanity checks. */
  445.     int        migFlags;         /* Flags used for migration. (Needs
  446.                       * to be reorganized to include things
  447.                       * currently in genFlags but that will
  448.                       * also require a world recompile.) */
  449.     Proc_Time   preEvictionUsage;      /* CPU usage (user + kernel)
  450.                       * as of the start of
  451.                       * eviction. */
  452.  
  453.     /*
  454.      * UNIX compatibility.
  455.      */
  456.  
  457.     int         unixErrno;               /* Errno for unix system call. */
  458.     /* 
  459.      * As a random convention, we'll set unixProgress to -1 if the 
  460.      * program is not in unix compatibility mode; otherwise 
  461.      * unixProgres != -1.
  462.      */
  463.     int         unixProgress;            /* Progress indicator for restarting
  464.                                             unix system calls. */
  465.  
  466.     /* 
  467.      * More lock instrumentation.  This should go with the LOCKDEP 
  468.      * fields above (if you're willing to do a world recompile).
  469.      */
  470.  
  471.     int        locksHeld;    /* number of locks currently held by 
  472.                  * the process; not necessarily the
  473.                  * same as lockStackSize because of
  474.                  * the way the stack is popped */
  475.  
  476. #ifdef SOSP91
  477.     /* 
  478.      * Fields for stashing away instrumentation information.
  479.      */
  480.     int        rememberedClient;
  481.     int        rememberedMig;
  482.     int        rememberedOp;
  483.     int        inNameLookup;
  484. #else
  485.     int        sospFields[4];    /* padding to keep the struct size constant */
  486. #endif
  487.  
  488.     /*
  489.      *---------------------------------------------------------------------
  490.      *
  491.      *  Extra padding, so that we can add fields to this struct 
  492.      *  without changing its size.
  493.      *
  494.      *---------------------------------------------------------------------
  495.      */
  496.  
  497.     int        extraField[5];        /* Extra fields for later use. */
  498.     
  499. } Proc_ControlBlock;
  500.  
  501. /*
  502.  * Exit-detach-wait monitor flags:
  503.  *
  504.  *  PROC_DETACHED        - This process is detached from its parent.
  505.  *                  When this process exits, it won't go on the
  506.  *                  exiting processes list.
  507.  *  PROC_WAITED_ON        - This process is detached and the parent has 
  508.  *                  already done a Proc_Wait on it.
  509.  *  PROC_SUSPEND_STATUS        - The process went into the suspended state
  510.  *                  and it hasn't been waited on yet.
  511.  *  PROC_RESUME_STATUS        - The process was resumed and it hasn't been 
  512.  *                  waited on yet.
  513.  *  PROC_STATUSES        - The union of the two above statuses.
  514.  */
  515.  
  516. #define PROC_DETACHED        0x01
  517. #define PROC_WAITED_ON        0x02
  518. #define    PROC_SUSPEND_STATUS    0x04
  519. #define    PROC_RESUME_STATUS    0x08
  520. #define    PROC_STATUSES        (PROC_SUSPEND_STATUS | PROC_RESUME_STATUS)
  521.  
  522. /*
  523.  * Information for encapsulating process state.
  524.  */
  525.  
  526. /*
  527.  * Identifiers to match encapsulated states and modules.
  528.  * Make sure to update PROC_MIG_NUM_CALLBACKS if one is added!
  529.  */
  530. typedef enum {
  531.     PROC_MIG_ENCAP_PROC,
  532.     PROC_MIG_ENCAP_VM,
  533.     PROC_MIG_ENCAP_FS,
  534.     PROC_MIG_ENCAP_MACH,
  535.     PROC_MIG_ENCAP_PROF,
  536.     PROC_MIG_ENCAP_SIG,
  537.     PROC_MIG_ENCAP_EXEC
  538. } Proc_EncapToken;
  539.  
  540. #define PROC_MIG_NUM_CALLBACKS 7
  541.  
  542. /*
  543.  * Each module that participates has a token defined for it.
  544.  * It also provides routines to encapsulate and deencapsulate data,
  545.  * as well as optional routines that may be called prior to migration
  546.  * and subsequent to migration.  This structure is passed around to
  547.  * other modules performing encapsulation.
  548.  */
  549. typedef struct {
  550.     Proc_EncapToken    token;        /* info about encapsulated data */
  551.     int            size;        /* size of encapsulated data */
  552.     ClientData        data;        /* for use by encapsulator */
  553.     int            special;    /* indicates special action required */
  554.     ClientData        specialToken;    /* for use during special action */
  555.     int            processed;    /* indicates this module did possibly
  556.                        destructive encapsulation operation
  557.                        and should be called to clean up
  558.                        on failure */
  559.  
  560. } Proc_EncapInfo;
  561.  
  562. #endif /* _PROCTYPES */
  563.